package com.lxl.fastexcel;

import cn.idev.excel.FastExcel;
import com.lxl.bo.DemoData;
import com.lxl.utils.ExcelUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author xiulong.liu
 * @Date 2024/12月/11/星期三 13:44
 * @Desc
 */
public class Demo01 {
    public static void main(String[] args) {
        String readFile = "F:\\demo.xlsx";
        // 创建一个名为“模板”的 sheet 页，并写入数据
        FastExcel.write(readFile, DemoData.class).sheet("模板").doWrite(data());
        String writeFile = "F:\\demo.xlsx";
        // 读取 Excel 文件
        FastExcel.read(writeFile, DemoData.class, new ExcelUtils.DemoDataListener()).sheet().doRead();
    }

    private static List<DemoData> data() {
        List<DemoData> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            DemoData data = new DemoData();
            data.setString("字符串" + i);
            data.setDate(new Date());
            data.setDoubleData(0.56);
            list.add(data);
        }
        return list;
    }

}
